//
//  InProgressContentView.m
//  RunOneZhangLu
//
//  Created by runone02 on 17/3/7.
//  Copyright © 2017年 runone. All rights reserved.
//。普通的view

#import "InProgressContentView.h"
#import "SDAutoLayout.h"

@interface InProgressContentView ()

@property (nonatomic, strong) UILabel *titleLabel; //标题
@property (nonatomic, strong) UILabel *showMessageLabel;//内容
@property (nonatomic, strong) UIView  *lineView; //

@property (nonatomic, copy) NSString *leftTitleStr;
@property (nonatomic, copy) NSString *contentStr;
@end

@implementation InProgressContentView

#pragma mark - lazyLoad



- (InProgressContentView *) initWithDefalutHeight:(CGFloat) height title:(NSString *)titleStr{
    _leftTitleStr = titleStr;
    return [self initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, height)];
}


-(instancetype)initWithFrame:(CGRect)frame {
    self=[super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:226.0 / 255 green:230.0 / 255 blue:240.0 / 255 alpha:1]];
        
        [self configUI];
        [self layoutUI];
    }
    return self;
}

- (void) configUI {
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.textAlignment = NSTextAlignmentRight;
    _titleLabel.text = _leftTitleStr;
    
    _showMessageLabel = [[UILabel alloc] init];
    _showMessageLabel.font          = [UIFont systemFontOfSize:15];
    _showMessageLabel.textAlignment = NSTextAlignmentLeft;
    //    _showMessageLabel.backgroundColor = [UIColor whiteColor];
    
    _lineView   = [UIView new];
    _lineView.backgroundColor = [UIColor whiteColor];
    [self sd_addSubviews:@[self.titleLabel, self.showMessageLabel,self.lineView]];
}

- (void) layoutUI {
    UIView *view =nil;
    if (_contentStr.length > 0) {
        view = self.showMessageLabel;
    }else {
        view = self.titleLabel;
    }
    self.titleLabel.sd_layout
    .leftSpaceToView(self, 0)
    .topSpaceToView(self,8)
    .widthIs(110)
    .heightIs(34)
    ;
    
    self.showMessageLabel.sd_layout
    .leftSpaceToView(self.titleLabel, 8)
    .rightSpaceToView(self, 8)
    .topSpaceToView(self,16)
    //    .heightIs(24)
    .autoHeightRatio(0);
    ;
    
    self.lineView.sd_layout
    .leftSpaceToView(self, 8)
    .rightSpaceToView(self, 8)
    .heightIs(1)
    .topSpaceToView(view,8)
    ;
    //
    
    [self setupAutoHeightWithBottomView:self.lineView bottomMargin:0];
}
#pragma mark -  设置
- (void) setContentString:(NSString *)contentStr {
    
    _showMessageLabel.text = contentStr;
    CGSize lblSize = [_showMessageLabel.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 126, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    if (lblSize.height > 34) {
        [self updateMyLayout];
    }
}

- (void) updateMyLayout {
    self.lineView.sd_layout
    .leftSpaceToView(self, 8)
    .rightSpaceToView(self, 8)
    .heightIs(1)
    .topSpaceToView(self.showMessageLabel, 8)
    ;
}

//- (void)layoutSubviews {
//    [super layoutSubviews];
////    [self ];
//
//}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
